<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/module.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><a href="<?php echo $cancel; ?>" class="button"><?php echo $button_cancel; ?></a></div>
    </div>
	<?php $module_row = 0; ?>
    <div class="content">
      <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
		<table class="form">
			<tr>
				<tr>
				  <td><?php echo $entry_layout; ?></td>
				  <td><select name="sparta_online_module[<?php echo $module_row; ?>][layout_id]">
					  <?php foreach ($layouts as $layout) { ?>
					  <?php if ($layout['layout_id'] == $module[0]['layout_id']) { ?>
					  <option value="<?php echo $layout['layout_id']; ?>" selected="selected"><?php echo $layout['name']; ?></option>
					  <?php } else { ?>
					  <option value="<?php echo $layout['layout_id']; ?>"><?php echo $layout['name']; ?></option>
					  <?php } ?>
					  <?php } ?>
					</select></td>
				</tr>
				<tr>
				  <td><?php echo $entry_position; ?></td>
				  <td><select name="sparta_online_module[<?php echo $module_row; ?>][position]">
					  <?php foreach( $positions as $pos ) { ?>
					  <?php if ($module[0]['position'] == $pos) { ?>
					  <option value="<?php echo $pos;?>" selected="selected"><?php echo $this->language->get('text_'.$pos); ?></option>
					  <?php } else { ?>
					  <option value="<?php echo $pos;?>"><?php echo $this->language->get('text_'.$pos); ?></option>
					  <?php } ?>
					  <?php } ?> 
					</select></td>
				</tr>
				<tr>
				  <td><?php echo $entry_status; ?></td>
				  <td><select name="sparta_online_module[<?php echo $module_row; ?>][status]">
					  <?php if ($module[0]['status']) { ?>
					  <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
					  <option value="0"><?php echo $text_disabled; ?></option>
					  <?php } else { ?>
					  <option value="1"><?php echo $text_enabled; ?></option>
					  <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
					  <?php } ?>
					</select></td>
				</tr>
				<tr>
					<td><?php echo $entry_sort_order; ?></td>
					<td class="right"><input type="text" name="sparta_online_module[<?php echo $module_row; ?>][sort_order]" value="<?php echo $module[0]['sort_order']; ?>" size="3" /></td>
				</tr>
		</table>
		<div class="vtabs">
			<?php $room_row = 1; ?>
			<?php foreach ($rooms as $room) { ?>
				<a href="#tab-room-<?php echo $room_row; ?>" id="room-<?php echo $room_row; ?>"><?php echo $tab_room . ' ' . $room_row; ?>&nbsp;<img src="view/image/delete.png" alt="" onclick="$('.vtabs a:first').trigger('click'); $('#room-<?php echo $room_row; ?>').remove(); $('#tab-room-<?php echo $room_row; ?>').remove(); return false;" /></a>
				<?php $room_row++; ?>
			<?php } ?>
			<span id="room-add"><?php echo $button_add_room; ?>&nbsp;<img src="view/image/add.png" alt="" onclick="addroom();" /></span> 
		</div>
		
		<?php $room_row = 1; ?>
		<?php foreach ($rooms as $room) { ?>
			<div id="tab-room-<?php echo $room_row; ?>" class="vtabs-content">
				<table class="form">
					<tr>
						<td><?php echo $entry_status; ?></td>
						<td><select name="room_setting[<?php echo $room_row; ?>][status]">
							<?php if($room['status']){ ?>
								<option value="1" selected="selected"><?php echo $text_enabled; ?></option>
								<option value="0"><?php echo $text_disabled; ?></option>
							<?php }else{ ?>
								<option value="1"><?php echo $text_enabled; ?></option>
								<option value="0" selected="selected"><?php echo $text_disabled; ?></option>
							<?php } ?>
						</select></td>
					</tr>
					<tr>
						<td><?php echo $entry_title; ?></td>
						<td><input type="text" name="room_setting[<?php echo $room_row; ?>][title]" value="<?php echo isset($room['title'])?$room['title']:'' ?>" size="100" /></td>
					</tr>
				</table>
				<table id="room_people_<?php echo $room_row; ?>" class="list">
					<thead>
						<tr>
							<td class="left"><?php echo $entry_name; ?></td>
							<td class="left"><?php echo $entry_yahoo_id; ?></td>
							<td class="left"><?php echo $entry_skype_id; ?></td>
							<td class="left"><?php echo $entry_phone; ?></td>
							<td class="left"><?php echo $entry_ext; ?></td>
							<td class="left"><?php echo $entry_status; ?></td>
							<td></td>
						</tr>
					</thead>
					<?php $row = 0; ?>
					<?php if (isset($room_people[$room_row])) { ?>
					<?php foreach ($room_people[$room_row] as $people) { ?>
						<tbody id="room-people-row<?php echo $room_row; ?><?php echo $row; ?>">
							<tr>
								<td><input type="text" name="room_people[<?php echo $room_row; ?>][<?php echo $row; ?>][name]" value="<?php echo isset($people['name'])?$people['name']:''; ?>" /></td>
								<td><input type="text" name="room_people[<?php echo $room_row; ?>][<?php echo $row; ?>][yahoo_id]" value="<?php echo isset($people['yahoo_id'])?$people['yahoo_id']:''; ?>" /></td>
								<td><input type="text" name="room_people[<?php echo $room_row; ?>][<?php echo $row; ?>][skype_id]" value="<?php echo isset($people['skype_id'])?$people['skype_id']:''; ?>" /></td>
								<td><input type="text" name="room_people[<?php echo $room_row; ?>][<?php echo $row; ?>][phone_number]" value="<?php echo isset($people['phone_number'])?$people['phone_number']:''; ?>" /></td>
								<td><input type="text" name="room_people[<?php echo $room_row; ?>][<?php echo $row; ?>][phone_ext]" value="<?php echo isset($people['phone_ext'])?$people['phone_ext']:''; ?>" /></td>
								<td><select name="room_people[<?php echo $room_row; ?>][<?php echo $row; ?>][status]">
									<?php if($people['status']){ ?>
										<option value="1" selected="selected"><?php echo $text_enabled; ?></option>
										<option value="0"><?php echo $text_disabled; ?></option>
									<?php }else{ ?>
										<option value="1"><?php echo $text_enabled; ?></option>
										<option value="0" selected="selected"><?php echo $text_disabled; ?></option>
									<?php } ?>
								</select></td>
								<td class="left"><a onclick="$('#room-people-row<?php echo $room_row; ?><?php echo $row; ?>').remove();" class="button"><?php echo $button_remove; ?></a></td>
							</tr>
						</tbody>
					<?php $row++; ?>
					<?php } ?>
					<?php } ?>
					
					<tfoot>
						<tr>
							<td colspan="6"></td>
							<td class="left"><a onclick="addPeople(this,<?php echo $room_row; ?>,<?php echo $row; ?>);" class="button"><?php echo $button_add; ?></a></td>
						</tr>
					</tfoot>
				</table>
			</div>
			<?php $room_row++; ?>
		<?php } ?>
		
		
      </form>
    </div>
  </div>
</div>

<script type="text/javascript"><!--
var room_row = <?php echo $room_row; ?>;
var row = 0;
function addroom() {	
	html  = '<div id="tab-room-' + room_row + '" class="vtabs-content">';
	html += '<table class="form">';
	html += '  <tr>';
	html += '  	<td><?php echo $entry_status; ?></td>';
	html += '    <td><select name="room_setting[' + room_row + '][status]">';
    html += '      <option value="1" selected="selected"><?php echo $text_enabled; ?></option>';
    html += '      <option value="0"><?php echo $text_disabled; ?></option>';
    html += '    </select></td>';
	html += '  </tr>';
	html += '  <tr>';
	html += '  	<td><?php echo $entry_title; ?></td>';
	html += '    <td><input type="text" name="room_setting[' + room_row + '][title]" value="" size="100" /></td>';
	html += '  </tr>';
	html += '</table>';
	
	html += '<table id="room_people_'+ room_row + '" class="list">';
	html += '<thead><tr>';
	html += '<td class="left"><?php echo $entry_name; ?></td>';
	html += '<td class="left"><?php echo $entry_yahoo_id; ?></td>';
	html += '<td class="left"><?php echo $entry_skype_id; ?></td>';
	html += '<td class="left"><?php echo $entry_phone; ?></td>';
	html += '<td class="left"><?php echo $entry_ext; ?></td>';
	html += '<td class="left"><?php echo $entry_status; ?></td>';
	html += '<td></td>';
	html += '</tr></thead>';
	html += '<tfoot>';
	html += '<tr>';
	html += '<td colspan="6"></td>';
	html += '<td class="left"><a onclick="addPeople(this,'+room_row+','+row+');" class="button"><?php echo $button_add; ?></a></td>';
	html += '	</tr>';
	html += '</tfoot>';
	html += '</table>';
	
	html += '</div>';
	
	$('#form').append(html);
	
	$('#room-add').before('<a href="#tab-room-' + room_row + '" id="room-' + room_row + '"><?php echo $tab_room; ?> ' + room_row + '&nbsp;<img src="view/image/delete.png" alt="" onclick="$(\'.vtabs a:first\').trigger(\'click\'); $(\'#room-' + room_row + '\').remove(); $(\'#tab-room-' + room_row + '\').remove(); return false;" /></a>');
	
	$('.vtabs a').tabs();
	
	$('#room-' + room_row).trigger('click');
	
	room_row++;
}
//--></script> 

<script type="text/javascript"><!--
function addPeople($bt_add,$room_row,$row) {
	var room_row = $room_row;
	var row = $row;
	var bt_add = $bt_add;
	html  = '<tbody id="room-people-row' + room_row + row + '">';
	html += '<tr>';
	html += '<td><input type="text" name="room_people['+room_row+']['+row+'][name]" value="" /></td>';
	html += '<td><input type="text" name="room_people['+room_row+']['+row+'][yahoo_id]" value="" /></td>';
    html += '<td><input type="text" name="room_people['+room_row+']['+row+'][skype_id]" value="" /></td>';
	html += '<td><input type="text" name="room_people['+room_row+']['+row+'][phone_number]" value="" /></td>';
	html += '<td><input type="text" name="room_people['+room_row+']['+row+'][phone_ext]" value="" /></td>';
    html += '    <td><select name="room_people['+room_row+']['+row+'][status]">';
    html += '      <option value="1" selected="selected"><?php echo $text_enabled; ?></option>';
    html += '      <option value="0"><?php echo $text_disabled; ?></option>';
    html += '    </select></td>';
	html += '<td class="left"><a onclick="$(\'#room-people-row' + room_row + row + '\').remove();" class="button"><?php echo $button_remove; ?></a></td>';
	html += '</tr>';
	html += '</tbody>';
	row++;
	html += '<tfoot>';
	html += '<tr>';
	html += '<td colspan="6"></td>';
	html += '<td class="left"><a onclick="addPeople(this,'+room_row+','+row+');" class="button"><?php echo $button_add; ?></a></td>';
	html += '	</tr>';
	html += '</tfoot>';
	$('#room_people_'+ room_row +'> tfoot').before(html);
	$(bt_add).parent().parent().parent().remove();
}
//--></script> 



<script type="text/javascript"><!--
$('.vtabs a').tabs();
//--></script>  
<?php echo $footer; ?>